﻿@{
    ViewBag.Title = "“4+7”集采药品使用监测表（按全院统计）";
}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-form-item">

                    <div class="layui-inline">

                        <label class="layui-form-label">批次筛选</label>
                        <div class="layui-input-inline" style="width:100px">
                            @*@Html.RelGroupPurchaseSelect("GroupPurchase", "")*@

                            <select id="setpc" name="setpc" lay-filter="setpc" lay-verify="required" lay-search>
                                <option value="0">全部</option>
                                <option value="1">正在执行</option>
                                <option value="2">已到期</option>
                            </select>

                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">集采批次</label>
                        <div class="layui-input-inline" style="width:250px">
                            @Html.RelGroupPurchaseSelect("GpCode", "")
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">药品</label>
                        <div class="layui-input-inline" style="width:200px">
                            <select name="drugCode" id="drugCode" lay-search>
                                <option value="">请选择药品</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">日期范围</label>
                        <div class="layui-inline" id="ID-laydate-range">
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-inline">
                            <button class="layui-btn" style="margin-left:20px; padding:0 25px;" id="btnQuery"> 查 询 </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                @*<script type="text/html" id="table-toolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="export">导出</button>
                        </div>
                    </script>*@
                <table id="LAY-report-list" lay-filter="LAY-report-list"></table>
            </div>
        </div>
    </div>
    <style>
        .layui-table-cell {
            font-size: 14px;
            padding: 0 5px;
            height: 50px;
            overflow: visible;
            text-overflow: inherit;
            white-space: normal;
            word-break: break-all;
        }
    </style>
    <script src="../layuiadmin/layui/layui.js"></script>
    <script type="text/javascript">
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'admin'], function () {
            var table = layui.table
                , form = layui.form
                , $ = layui.$
                , admin = layui.admin
                , laydate = layui.laydate
                , util = layui.util;
            initTableBtn(table);
            RenderData();
            // 日期范围 - 左右面板独立选择模式
            laydate.render({
                elem: '#ID-laydate-range',
                range: ['#ID-laydate-start-date', '#ID-laydate-end-date']
            });
            //监听批次筛选下拉框
            form.on('select(setpc)', function (data) {
                var type = data.value;
                aa = type;
                //console.log(type);
                $.ajax({
                    type: 'post',
                    url: '/GroupChoseDrugCompare/GetGroupInfo',
                    data: "param=" + type,
                    //dataType: 'json',
                    success(res) {
                        var str = '<option value="">请选择集采批次</option>';
                        for (var i in res) {
                            str += "<option value='" + res[i].Code + "'>" + res[i].Year + " " + res[i].Name + "</option>";
                        }
                        $('#GpCode').html(str)
                        form.render();
                    }
                })
                //console.log(data)
            });

            //监听集采批次下拉框
            form.on('select(GpCode)', function (data) {
                var type = data.value;
                $.ajax({
                    type: 'post',
                    url: '/GroupChoseDrugCompare/GetChoseDrugInfo',
                    data: "gpcode=" + type,
                    success(res) {
                        var str = '<option value="">请选择药品</option>';
                        for (var i in res) {
                            str += "<option value='" + res[i].DrugCode + "'>" + res[i].DrugName + "</option>";
                        }
                        $('#drugCode').html(str)
                        form.render();
                    }
                })
            });

            $(document).ready(function () {
                $("#btnQuery").click(function () {
                    RenderData("2");
                });


            });
            function RenderData(type) {

                var gpcode = $("#GpCode").val();
                var drugcode = $("#drugCode").val();
                var beginDate = $("#ID-laydate-start-date").val();
                var endDate = $("#ID-laydate-end-date").val();
                if (type == "2") {
                    if (gpcode == "") {
                        alert("请先选择集采批次");
                        return;
                    }
                    if (beginDate == "" || endDate == "") {

                        alert("请选择日期范围");
                        return;
                    }
                }

                table.render({
                    elem: '#LAY-report-list'
                    , height: 'full-100'
                    , url: '/Report/GetWholePurList?gpCode=' + gpcode + '&drugCode=' + drugcode + '&beginDate=' + beginDate + '&endDate=' + endDate //模拟接口
                    , toolbar: '#table-toolbar'
                    , method: 'post'
                    , cols: [[
                        { field: 'GpName', title: '集采批次', width: 300, fixed: 'left', align: 'center' }
                        , { field: 'DrugName', title: '中选药品名称', width: 280, fixed: 'left', align: 'center' }
                        , { field: 'Specs', title: '规格', width: 200, fixed: 'left', align: 'center' }
                        , { field: 'ProducerName', title: '生产厂家', width: 180, align: 'center' }
                        , { field: 'UnitPrice', title: '单价', width: 100, align: 'center' }
                        , { field: 'TaskQTY', title: '任务量', width: 100, align: 'center' }
                        //, { field: 'PackQty', title: '药品包装数量', width: 130, align: 'center' }
                        , { field: 'drugPurNum', title: '中选药品总采购数量', width: 100, align: 'center' }
                        , { field: 'InNum', title: '中选药品当前时间采购数量', width: 100, align: 'center' }
                        , { field: 'MinUnit', title: '单位', width: 100, align: 'center' }

                    ]]
                    , page: true
                    , limit: 10
                    , limits: [10 , 20, 30,50,100]
                    , text: { none: '暂无数据' }
                });
            }


            //头工具栏事件
            table.on('toolbar(LAY-report-list)', function (obj) {
                switch (obj.event) {
                    case 'export':
                        var form = document.createElement('form');
                        form.action = '/Report/ExportWhole';
                        form.method = 'post';
                        var opt = document.createElement('input');
                        opt.name = 'GpCode';
                        opt.value = $("#GpCode").val();
                        form.appendChild(opt);
                        opt = document.createElement('input');
                        opt.name = 'drugCode';
                        opt.value = $("#drugCode").val();
                        form.appendChild(opt);
                        $(document.body).append(form);
                        form.submit();
                        break;
                };
            });
            //监听搜索
            form.on('submit(LAY-report-search)', function (data) {
               


                var field = data.field;
                //执行重载
                table.reload('LAY-report-list', {
                    where: field,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
        });
    </script>


